﻿'<HandleError()> _
Public Class AdminController
    Inherits System.Web.Mvc.Controller

#Region "Edit Races"

    <Authorize(Roles:="Administrator")> _
    <AcceptVerbs(HttpVerbs.Get)> _
    Function EditRaces() As ActionResult
        Dim model As New EditRacesViewModel
        Using db As New TyranntDataContext
            Dim vm As New RaceListViewModel
            vm.RaceList = db.GetRaces()
            model.RaceListViewModel = vm
            model.RaceInfoImages = db.GetImageDetails("race", "info")
            model.RacePortraitPicture = db.GetImageDetails("race", "portrait")
            Return View(model)
        End Using
    End Function

#End Region


#Region "Edit Images"

    ' Ajax routines
    Public Function GetImageDetails(ByVal imageUrl As String) As JsonResult
        Dim img As New imageDetail
        Using db As New TyranntDataContext
            Dim dbimg As image = db.GetImage(imageUrl)
            img.ImageName = dbimg.name
            img.ImageTag = dbimg.tag
            img.ImageType = dbimg.type
            img.ImageURL = dbimg.url
        End Using
        Return (Json(img))
    End Function

    Public Function UpdateImageDetails(ByVal imageName As String, ByVal imageUrl As String, ByVal imageType As String, ByVal imageTag As String) As JsonResult
        Dim result As String = ""
        Using db As New TyranntDataContext
            result = db.Updateimage(imageName, imageUrl, imageType, imageTag)
        End Using
        Return Json(result)
    End Function

    Public Function DeleteImage(ByVal imageName As String) As JsonResult
        Dim result As String = ""
        Using db As New TyranntDataContext
            result = db.Deleteimage(imageName)
        End Using
        Return Json(result)
    End Function

    <AcceptVerbs(HttpVerbs.Get)> _
    Public Function GetImageList() As ActionResult
        Dim model As New ImageListViewModel
        Using db As New TyranntDataContext
            model.ImageList = db.GetImages("")
        End Using
        Return View("ImageList", model)
    End Function


    ' Action routines
    <Authorize(Roles:="Administrator")> _
    <AcceptVerbs(HttpVerbs.Get)> _
    Function EditImages() As ActionResult
        Dim model As New EditImagesViewModel
        Using db As New TyranntDataContext
            Dim ilModel As New ImageListViewModel
            ilModel.ImageList = db.GetImages("")
            model.ImageListViewModel = ilModel
        End Using
        Return View(model)
    End Function

#End Region

End Class